<?php
/**
 * Created by PhpStorm.
 * User: N
 * Date: 2017/12/13
 * Time: 15:17
 */
namespace common\models;

use Yii;
use yii\base\Model;
use common\models\Models;
use backend\modules\content\models\Sitemodel;
use backend\modules\content\models\Modelfield;
use yii\db\ActiveRecord;
use yii\data\ActiveDataProvider;
use yii\data\Pagination;


/**
 * This is the model class for table "category".
 *
 * @property string $catid
 * @property string $siteid
 **/
class Negative extends ActiveRecord
{
     /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%negative}}';
    }



    /**
    * 验证规则
    */
    public function rules()
    {
        return [
            [['title'],'required','message'=>'不能为空'],
            [['title'],'string'], 
            [['id'],'number'],   
            [['uid','meet_id','reason','branch_id','attaches'],'default'],
            [['content'],'string'],              
        ];
    }

    public function beforeSave($insert){
        if($insert){
            $this->status=0;
            //插入时补充操作
            $this->add_time = time();
        }else{
            //修改时补充操作

        }
      
        return true;

    }



    public function getBranches()
    {

        if($this->branch_id)
        {
            $this->branch_id = trim($this->branch_id,',');
            $branches=Branch::find('')->where("status=0 and id in ({$this->branch_id})")->orderBy('id desc')->all();
            return $branches;
        }
        else
        {
            return '';
        }

    }


    public function getUser()
    {

        $user = User::findOne(['id'=>$this->uid]);
        return $user->realname;
    }


            /**
     * 获取附件列表
     */
    public function getAttachlist()
    {
        if($this->attaches)
        {
            $attachids=explode(',',$this->attaches);
            foreach($attachids as $tt)
            {
                if($tt)
                    $temps[]=$tt;
            }
            $astr=implode(',',$temps);
            $attaches=Attachment::find('')->where("status=0 and aid in ({$astr})")->orderBy('aid desc')->all();
            return $attaches;
        }
        else
        {
            return [];
        }
    }






        /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'title' => '标题',
            'reason'=>'原因',
            'content' => '备注',
            'add_time'=>'添加时间',
        ];
    }

    


}